package com.sikaryofficial.workbench.domain.eo;

import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.sikaryofficial.workbench.constant.DictConstant;
import com.sikaryofficial.workbench.constant.GoodsListingStatusEnum;
import com.sikaryofficial.workbench.utils.excel.annotation.ExcelDict;
import com.sikaryofficial.workbench.utils.excel.annotation.ExcelEnum;
import com.sikaryofficial.workbench.utils.excel.converter.DictStringStringConverter;
import com.sikaryofficial.workbench.utils.excel.converter.EnumIntegerStringConverter;
import com.sikaryofficial.workbench.utils.excel.converter.goods.GoodsTasteConverter;
import com.sikaryofficial.workbench.utils.excel.converter.goods.PriceTierConverter;
import lombok.Data;
import org.hibernate.validator.constraints.UniqueElements;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;

@ExcelIgnoreUnannotated
@Data
public class GoodsEO {

    /**
     * 产品名称
     */
    @ExcelProperty(index = 0)
    @NotEmpty(message = "产品名称不能为空")
    private String goodsName;

    /**
     * 币种
     */
    @ExcelProperty(index = 1, converter = DictStringStringConverter.class)
    @ExcelDict(DictConstant.DICT_TYPE_CURRENCY)
    @NotEmpty(message = "币种不能为空")
    private String currency;

    /**
     * 单价-零售价
     */
    @ExcelProperty(index = 2)
    @NotNull(message = "零售定价-原价不能为空")
    private BigDecimal unitPrice;
    /**
     * 单价-零售价-现价
     */
    @ExcelProperty(index = 3)
    private BigDecimal currentUnitPrice;

    /**
     * 批发价格
     */
    @ExcelProperty(index = 4)
    @NotNull(message = "批发价格-原价不能为空")
    private BigDecimal wholesaleUnitPrice;
    /**
     * 批发价格-现价
     */
    @ExcelProperty(index = 5)
    private BigDecimal currentWholesaleUnitPrice;

    /**
     * 阶梯价字符串
     */
    @ExcelProperty(index = 6, converter = PriceTierConverter.class)
    private List<@Valid PriceTierEO> priceTiers;

    /**
     * 口味
     */
    @ExcelProperty(index = 7, converter = GoodsTasteConverter.class)
    @NotEmpty(message = "口味不能为空")
    private List<@Valid GoodsTasteEO> goodsTastes;

    @UniqueElements(message = "口味名称重复[{duplicates}]")
    public List<String> getCheckRepeatResult() {
        return goodsTastes == null
                ? null
                : goodsTastes.stream().map(GoodsTasteEO::getTasteName).collect(Collectors.toList());
    }

    /**
     * 商品描述
     */
    @ExcelProperty(index = 8)
    @NotEmpty(message = "描述不能为空")
    private String goodsDesc;
    /**
     * 商品参数
     */
    @ExcelProperty(index = 9)
    @NotEmpty(message = "参数不能为空")
    private String goodsSpec;

    /**
     * 上下架状态：0-未上架 1-已上架
     *
     * @see GoodsListingStatusEnum
     */
    @ExcelProperty(index = 10, converter = EnumIntegerStringConverter.class)
    @ExcelEnum(value = GoodsListingStatusEnum.class, code = "code", text = "desc")
    @NotNull(message = "状态不能为空")
    private Integer listingStatus;

    /**
     * 款式: style:disposable 一次性,cartridge 弹药筒,other 其他
     */
    @ExcelProperty(index = 11, converter = DictStringStringConverter.class)
    @ExcelDict(DictConstant.DICT_TYPE_GOODS_STYLE)
    @NotEmpty(message = "款式不能为空")
    private String style;

    /**
     * 品牌编码
     */
    @ExcelProperty(index = 12)
    @NotEmpty(message = "品牌不能为空")
    private String brandNo;

    /**
     * 口吸数
     */
    @ExcelProperty(index = 13)
    @NotNull(message = "口吸数不能为空")
    private Integer puffNum;

    /**
     * 尼古丁含量, 单位：mg/ml
     */
    @ExcelProperty(index = 14)
    @NotNull(message = "尼古丁含量不能为空")
    private Integer nicotineCapacity;

    /**
     * 烟油容量, 单位：毫升 ml
     */
    @ExcelProperty(index = 15)
    @NotNull(message = "烟油容量不能为空")
    private Integer liquidCapacity;

    /**
     * 电池容量，单位： 毫安小时 mAh
     */
    @ExcelProperty(index = 16)
    @NotNull(message = "电池容量不能为空")
    private Integer batteryCapacity;

}
